﻿using System;
using System.Collections.Generic;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.Text;
using System.Linq;
using System.Collections.Concurrent;
using AccountingServices.BLO;
using log4net;
using AccountingModel.BLO;
using AccountingModel.DTO;

namespace AccountingServices
{
    // NOTE: You can use the "Rename" command on the "Refactor" menu to change the class name "Service1" in code, svc and config file together.
    public class AccountingServices : IAccountingServices
    {
        static AccountingServices()
        {
            //using (AccountingModelContainer db = Schema.ModelFactory.getInstance())
            //{
            //    if (!db.DatabaseExists())
            //    {
            //        Logger.Info("Database not found. Created a new one.");
            //        db.CreateDatabase();
            //    }
            //}
        }

        private static readonly ILog Logger = LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);

        private readonly TransactionManager transactionManager = TransactionManager.GetInstance();
        private readonly AccountManager accountManager = AccountManager.GetInstance();

        public DateTime GetServerTime()
        {
            return DateTime.Now;
        }
        
        public int InsertTransaction(DTOTransaction transaction)
        {
            return transactionManager.InsertTransaction(transaction);
        }

        public string RemoveTransaction(int Id)
        {
            return transactionManager.RemoveTransaction(Id);
        }

        public string EditTransaction(DTOTransaction transaction)
        {
            return transactionManager.EditTransaction(transaction);
        }

        public DTOTransaction GetTransaction(int id)
        {
            return transactionManager.GetTransaction(id);
        }

        public List<DTOTransaction> GetTransactions(DateTime fromDate, DateTime toDate)
        {
            return transactionManager.GetTransactions(fromDate, toDate);
        }

        public int AddAccount(string accountName)
        {
            return accountManager.AddAccount(accountName);
        }

        public string RemoveAccount(int Id)
        {
            return accountManager.RemoveAccount(Id);
        }

        public string EditAccount(DTOAccount account)
        {
            return accountManager.EditAccount(account);
        }

        public List<DTOAccount> GetAccountList()
        {
            return accountManager.GetAccountList();
        }

        public decimal GetBalance(IList<int> accountIds, DateTime atTime)
        {
            return accountManager.GetBalance(accountIds, atTime);
        }

        public IList<DTOAccountActivity> GetAccountActivities(IList<int> AccountIds, DateTime fromDate, DateTime toDate)
        {
            return accountManager.GetAccountActivities(AccountIds, fromDate, toDate);
        }

        public IList<DTOAccountSummary> GetAccountSummaries(IList<int> AccountIds, IList<DateTime> points)
        {
            return accountManager.GetAccountSummaries(AccountIds, points);
        }
    }
}
